package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.godpaper.as9.bussiness.delegates.MessageDelegate;
	import com.godpaper.as9.events.GetMessageListEvent;
	import com.godpaper.as9.events.GetPhotoInfoEvent;
	import com.godpaper.as9.events.SetMessageInfoEvent;
	import com.godpaper.as9.model.MessageModelLocator;
	import com.godpaper.as9.model.PhotoModelLocator;
	
	import mx.rpc.IResponder;

	public class SetMessageInfoCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:MessageDelegate;
		private var messageModel:MessageModelLocator =  MessageModelLocator.getInstance();
		private var setMessageInfoEvent:SetMessageInfoEvent;
		[Bindable]private var photoModel:PhotoModelLocator = PhotoModelLocator.getInstance();
		public function SetMessageInfoCommand()
		{
			super();
			delegate = new MessageDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			setMessageInfoEvent = SetMessageInfoEvent(event);
			delegate.create(setMessageInfoEvent.messageInfo);
		}
		
		override public function result(data:Object):void
		{
			trace("setMessageInfo: "+data.result.info);
			if(data.result.info=="success")
			{
				CairngormEventDispatcher.getInstance().dispatchEvent(new GetMessageListEvent(photoModel.photoInfo.pno));
				CairngormEventDispatcher.getInstance().dispatchEvent(new GetPhotoInfoEvent(photoModel.photoInfo.pno));
			}
		}
		
	}
}